package com.kstudio.videocapture.listfile.fileaction;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.kstudio.videocapture.R;
import com.kstudio.videocapture.util.KLog;

public class KFileActionAdapter extends ArrayAdapter<KFileActionItem> {
    private final KLog log = new KLog("KFileList");

    private static final int ICON_FOLDER        = R.drawable.klist_folder;

    private final LayoutInflater         mInflater;

    public KFileActionAdapter(Context context, ArrayList<KFileActionItem> objects) {
        super(context, 0, objects);

        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        KFileActionAdapterWrapper viewWrapper;

        if(view == null) {
            view = mInflater.inflate(R.layout.file_action_row, null);
            viewWrapper = new KFileActionAdapterWrapper(view);
            view.setTag(viewWrapper);
        } else {
            viewWrapper = (KFileActionAdapterWrapper)view.getTag();
        }

        final KFileActionItem data = this.getItem(position);

        if(data != null) {
            if(data.getFileType() == KFileActionItem.FOLDERUP) {
                viewWrapper.getIcon().setImageResource(ICON_FOLDER);
                viewWrapper.getName().setText(data.getName());
            } else if(data.getFileType() == KFileActionItem.FOLDER) {
                viewWrapper.getIcon().setImageResource(ICON_FOLDER);
                viewWrapper.getName().setText(data.getName());
            }
        }
        return view;
    }
}
